Conditions | 3 |
Total Lines | 48 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { CommandHandler } from '@nestjs/cqrs'; |
||
16 | |||
17 | public async execute(command: UpdateSchoolCommand): Promise<string> { |
||
18 | const { |
||
19 | id, |
||
20 | reference, |
||
21 | address, |
||
22 | city, |
||
23 | name, |
||
24 | email, |
||
25 | zipCode, |
||
26 | numberOfClasses, |
||
27 | numberOfStudents, |
||
28 | status, |
||
29 | type, |
||
30 | observation, |
||
31 | phoneNumber |
||
32 | } = command; |
||
33 | |||
34 | const school = await this.schoolRepository.findOneById(id); |
||
35 | if (!school) { |
||
36 | throw new SchoolNotFoundException(); |
||
37 | } |
||
38 | |||
39 | if ( |
||
40 | reference !== school.getReference() && |
||
41 | true === (await this.isSchoolAlreadyExist.isSatisfiedBy(reference)) |
||
42 | ) { |
||
43 | throw new SchoolAlreadyExistException(); |
||
44 | } |
||
45 | |||
46 | school.update( |
||
47 | reference, |
||
48 | name, |
||
49 | address, |
||
50 | zipCode, |
||
51 | city, |
||
52 | status, |
||
53 | type, |
||
54 | email, |
||
55 | phoneNumber, |
||
56 | numberOfStudents, |
||
57 | numberOfClasses, |
||
58 | observation |
||
59 | ); |
||
60 | |||
61 | await this.schoolRepository.save(school); |
||
62 | |||
63 | return school.getId(); |
||
64 | } |
||
66 |